package com.example.administrator.myproject.View;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

import com.example.administrator.myproject.GlobalConfig;
import com.example.administrator.myproject.IView.IMainActivity;
import com.example.administrator.myproject.Prensent.UserPresenter;
import com.example.administrator.myproject.R;
import com.example.administrator.myproject.beans.UserInfo;

import org.json.JSONObject;

import java.util.List;

public class MainActivity extends AppCompatActivity implements IMainActivity {
    private long exitTime = 0;
    private UserPresenter userPresenter=new UserPresenter(this,this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(this,"ddd",Toast.LENGTH_SHORT).show();
        userPresenter.getDataFromGithub(GlobalConfig.userName,GlobalConfig.pwd);
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
            if((System.currentTimeMillis()-exitTime) > 2000){
                Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
                super.onDestroy();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void loginSuccess(JSONObject jsonObject) {

    }

    @Override
    public void getDataSuccess(List<UserInfo> gitUserList) {
        for(UserInfo githubUser : gitUserList){
            System.out.println("-=-=-=-=>>toString() = " + githubUser.toString());
        }
        Log.d("daas","ok");
        Toast.makeText(this,"dadad",Toast.LENGTH_SHORT).show();
    }
}
